#include "StdAfx.h"
#include "ModulatorThread.h"
#include "Locator.h"
#include "ModulatorStream.h"
#include "SampleBuffer.h"
#include "LoqModulatorStream.h"

#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif

ModulatorThread::ModulatorThread(void)
{
	isRunning = false;
	loqModulatorStream = new LoqModulatorStream();
}

ModulatorThread::~ModulatorThread(void)
{
	delete loqModulatorStream;
}

void ModulatorThread::Run()
{
	isRunning = true;
	while(isRunning)
	{
		FillBuffers();
	}
}

void ModulatorThread::Stop()
{
	isRunning = false;
	loqModulatorStream->Reset();
	Thread::Terminate();
}

void ModulatorThread::FillBuffers()
{
	Locator* locator = Locator::Instance();	
	//Sample* sample = locator->GetModulatorStream()->GetData();	
	Sample* sample = loqModulatorStream->GetData();
	if(sample)
	{
		//locator->GetModulatorBuffer()->Write(sample);
		delete sample;
	}	
	try 
	{
		//Sleep(1);
	}
	catch(...){}
}